from includes import *
from Gui.Gui import *
from Gui.GuiWnd import *
from Gui.GuiImg import *
from Gui.GuiBtn import *

from gameState import *

class MainMenuWidget:
	def __init__(self, state_):
		
		self.screen = pygame.display.get_surface()
		screenW = self.screen.get_width()
		screenH = self.screen.get_height()
		menuW = 250
		menuH = 250
		self.state = state_
		
		background = GuiImg(0,0,"data/images/menubg.jpg")
		self.state.gui.add(background)
		self.window = GuiWnd((screenW/2) - (menuW/2), (screenH/2) - (menuH/2), menuW, menuH, "Main Menu", "data/fonts/bitstream.ttf")
		
		newGameButton = GuiBtn(50, 50, 150, 30, "New Game", "data/fonts/bitstream.ttf", 12)
		newGameButton.onClick.append(self.clickedNewGame)
		
		loadGameButton = GuiBtn(50, 85, 150, 30, "TODO: Load Game", "data/fonts/bitstream.ttf", 12)
		loadGameButton.onClick.append(self.clickedLoadGame)
		
		settingsButton = GuiBtn(50, 120, 150, 30, "TODO: Settings", "data/fonts/bitstream.ttf", 12)

		quitButton = GuiBtn(50, 155, 150, 30, "Quit", "data/fonts/bitstream.ttf", 12)
		quitButton.onClick.append(self.clickedQuit)

		if not pygame.mixer.music.get_busy():
			#print "loading music"
			#CHANGE ME when we get a real track.
			pygame.mixer.music.load("data/music/deleteme.title.mp3")
			#print "playing music"
			pygame.mixer.music.play(-1) #Loop this track indefinately
		
		self.window.add(newGameButton)
		self.window.add(loadGameButton)
		self.window.add(settingsButton)
		self.window.add(quitButton)
		self.state.gui.add(self.window)
		
			
		# Events that connect to the buttons on the menu.
	def clickedNewGame(self, clicked_, gui_):
		pygame.mixer.music.fadeout(555) #Fadeout music for half a second, then change states.
		self.state.nextState = gameState()
		
	def clickedLoadGame(self, clicked_, gui_):
		#Don't fadeout if we're going to load game dialog #pygame.mixer.music.fadeout(555) #Fadeout music for half a second, then change states.
		self.state.nextState = loadState()
		
	def clickedQuit(self, clicked_, gui_):
		pygame.mixer.music.fadeout(555) #Fadeout music for half a second, then change states.
		self.state.run = 0
